﻿@model Object
@using System.ComponentModel;
@using System.Reflection;
@using NewLife.Reflection;
@{
    Layout = NewLife.Cube.Setting.Current.Layout;

    var Obj = Model as Object;
    var dic = ViewBag.Properties as Dictionary<String, List<PropertyInfo>>;
}
<div class="row">
    @Html.Partial("_Object_Nav", Model)
</div>
<div class="row">
    <div class="col-md-12">
        <div class="form-horizontal">
            @using (Html.BeginForm("Update", null))
            {
                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)
                foreach (var item in dic)
                {
                    if (dic.Count > 1)
                    {
                        <div class="form-group col-sm-12 col-md-12 col-xd-12">
                            <label class="control-label col-xs-2 col-md-3 no-padding-left">
                                <h2>@item.Key</h2>
                            </label>
                        </div>
                    }
                    foreach (var pi in item.Value)
                    {
                        var name = pi.Name;
                        var dis = pi.GetDisplayName();
                        var des = pi.GetDescription();
                        if (dis.IsNullOrEmpty() && !des.IsNullOrEmpty()) { dis = des; des = null; }
                        if (!dis.IsNullOrEmpty() && des.IsNullOrEmpty() && dis.Contains("。"))
                        {
                            des = dis.Substring("。");
                            dis = dis.Substring(null, "。");
                        }
                        <div class="form-group col-sm-12 col-md-12">
                            <label class="control-label col-xs-2 col-md-3 no-padding-left" for="@pi.Name">@(dis ?? pi.Name)</label>
                            <div class="input-group col-xs-10 col-md-4">
                                @Html.ForEditor(pi.Name, Obj.GetValue(pi), pi.PropertyType)
                                @Html.ValidationMessage(pi.Name)
                            </div>
                            <span class="hidden-xs col-md-5">&nbsp; @des</span>
                        </div>
                    }
                }
                if (this.Has(PermissionFlags.Update))
                {
                    <div class="clearfix form-actions col-sm-12 col-md-12">
                        <label class="control-label col-xs-4 col-sm-5 col-md-5"></label>
                        <button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-save"></i><strong>保存</strong></button>
                        <button type="button" class="btn btn-danger" onclick="history.go(-1);"><i class="glyphicon glyphicon-remove"></i><strong>取消</strong></button>
                    </div>
                }
            }
        </div>
    </div>
</div>